package jaxb.handlers;

import jaxb.DataStoreException;
import jaxb.ReaderWriter;
import jaxb.generated.Coordenadas2DXml;
import jaxb.generated.DataCirculoXml;
import jaxb.generated.DataFlowersXml;
import jaxb.generated.ObjectFactory;
import jaxb.generated.PuntoVectorXml;
import figuras.PuntoVector;

/**
 * Handles access to an underlying JAXB Users data source and provides select
 * methods to return various subsets of the data based on the search criteria
 * passed in.
 */
public class DatosFlorHandler extends JAXBReaderWriterHandler{
    
    
    /**
     * The object factory object
     */
    private static ObjectFactory factory = new ObjectFactory();
    
    /** Creates a new instance of FtpUsersHandler
     *
     * @param readerWriter The ReaderWriter object to be read from/written to
     * @param fileExistsOnDisk The file exists on disk
     * @throws es.sgi.spf.jaxb.common.DataStoreException if the data cannot be read
     */
    public DatosFlorHandler(ReaderWriter readerWriter, boolean fileExistsOnDisk)
    throws DataStoreException {
        super(DataFlowersXml.class.getPackage().getName(),
                readerWriter, fileExistsOnDisk);
    }
    
    /**
     * Initialises data objects in the event we are not reading a data file at
     * creation time. See 'autoLoad' parameter in constructor.
     */
    public void init() {
        
        DataFlowersXml dataFlowers=factory.createDataFlowersXml();
        
        // Save the data
        super.setData(dataFlowers);
    }
    
    /**
     * Writes into file the nodes
     * @throws es.sgi.spf.jaxb.common.DataStoreException If an error occurs
     * writing to the the file.
     */
    public void writeToFile() throws DataStoreException{
        super.store();
    }
    
    public void addCoordenadas2DToDataCirculoXml(DataCirculoXml dataCirculo,PuntoVector p2d,
    		double anguloY,double anguloZ,String file){
    	PuntoVectorXml pv = factory.createPuntoVectorXml();
    	pv.setX(p2d.getX());
    	pv.setY(p2d.getY());
    	pv.setZ(p2d.getZ());
    	Coordenadas2DXml c2dxml = factory.createCoordenadas2DXml();
    	c2dxml.setPuntoVectorXml(pv);
    	c2dxml.setAnguloY(anguloY);
    	c2dxml.setAnguloZ(anguloZ);
    	c2dxml.setFile(file);
    	dataCirculo.getCoordenadas2DXml().add(c2dxml);    	
    }
    
    public DataCirculoXml createDataCirculoXml(){
    	return factory.createDataCirculoXml();
    }
    
    public void addDataCirculoXml(DataCirculoXml datacirculo) throws DataStoreException{
    	this.getDataFlowersXml().getDataCirculoXml().add(datacirculo);
    	//super.store();
    }
    
   public void setReceptaculoFile(String file) throws DataStoreException{
	   this.getDataFlowersXml().setReceptaculoFile(file);
	   //super.store();
   }

    public DataFlowersXml getDataFlowersXml()
    throws DataStoreException {
        return (DataFlowersXml)super.getData();
    }


}
